package com.sudo.boot.admin._sys.my;

import com.sudo.boot.base.pojo.JsonRes;
import com.sudo.boot.mapper.sys.model.bo.my.MyUserBoEdit;
import com.sudo.boot.mapper.sys.model.bo.my.MyUserBoPassword;
import com.sudo.boot.mapper.sys.model.vo.SysUserDetailVo;
import com.sudo.boot.mapper.sys.model.vo.my.MyUserInfoVo;
import com.sudo.boot.satokensso.util.BootStpUtil;
import com.sudo.boot.service.sys.SysUserService;
import com.sudo.boot.service.sys_my.MyUserService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("my-user")
public class MyUserController {

    @Resource
    private SysUserService sysUserService;

    @Resource
    private MyUserService myUserService;

    /**
     * 查询我的信息
     */
    @GetMapping("detail")
    public JsonRes<SysUserDetailVo> get() {
        SysUserDetailVo detailVo = sysUserService.detailById(BootStpUtil.getCurrUserId());
        return JsonRes.ok(detailVo);
    }

    /**
     * 编辑我的用户信息 。
     *
     * @param bo 用户信息
     */
    @PostMapping("edit")
    public JsonRes<Void> edit(@RequestBody @Validated MyUserBoEdit bo) {
        myUserService.edit(bo);
        return JsonRes.ok();
    }

    /**
     * 密码重置 。
     *
     * @param bo 密码信息
     */
    @PostMapping("resetPassword")
    public JsonRes<Void> resetPassword(@RequestBody @Validated MyUserBoPassword bo) {
        myUserService.resetPassword(bo);
        return JsonRes.ok();
    }

    /**
     * 查询我的当前用户 。
     */
    @GetMapping("getMyUserInfo")
    public JsonRes<MyUserInfoVo> getMyUserInfo() {
        MyUserInfoVo myUserInfo =  myUserService.getMyUserInfo();
        return JsonRes.ok(myUserInfo);
    }
}
